package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePermissionFunctionsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新权限功能
func NewUpdatePermissionFunctionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePermissionFunctionsLogic {
	return &UpdatePermissionFunctionsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePermissionFunctionsLogic) UpdatePermissionFunctions(req *types.UpdatePermissionFunctionsRequest) error {
	_, err := l.svcCtx.AuthRoleRpc.UpdatePermissionFunctions(l.ctx, &v1.UpdatePermissionFunctionsRequest{
		PermissionId: req.PermissionId,
		FunctionIds:  req.FunctionIds,
	})

	return err
}
